<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\lak\Residential;

class Love extends Model
{
    use HasFactory;

    protected $table = 'love';

    /**
     * 一个用户可以用多个房源
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function love()
    {
        return $this->hasOne(Residential::class, 'id', 'fang_id');
    }


    protected $fillable = ['house_name', 'address', 'developers', 'building_types', 'flat_type', 'house_type',
        'area', 'price', 'floor_plan', 'traffic_condition', 'surrounding_facility', 'sales_link', 'created_at', 'updated_at'
    ];

    protected $casts = [
        'house_name' => 'string',
        'address' => 'string',
        'developers' => 'string',
        'area' => 'double',
        'price' => 'float'
    ];

    //多条件搜索分页
    public static function getSecharvr($params, $limit, $offset)
    {
        $data = self::where('is_del', 0)->paginate(7);//offset是偏移量; //mit展示每页条数

        return $data;
    }

    //详情
    static function detail($where)
    {
        return self::where($where)->first();
    }



}
